package com.example.demo;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/Request")

public class RequestController {
    @RequestMapping("/request")
    public String request(String keyword){
        return "关键词："+keyword;
    }
    @RequestMapping("/r")
    public String r(@RequestParam("q") String keyword){
        return "关键词："+keyword;
    }
    @RequestMapping("/r2")
    public String list(@RequestParam  List<String> list){
        return "返回值:"+list;
    }
    //传一个Json
    @RequestMapping("/r3")
    public String r3(@RequestBody User user){
        return user.toString();
    }
    //传一个文件并保存到本地
    @RequestMapping("/r4")
    public String r4(MultipartFile file) throws IOException {
        System.out.println(file.getOriginalFilename());
        file.transferTo(new File("D:\\JavaProject",file.getOriginalFilename()));
        return "文件获取成功";
    }
    //从url中获取路径参数
    @RequestMapping("/article/{Userid}/{type}")
    public String r5(@PathVariable Integer Userid,@PathVariable int type){
        return "userid:"+Userid+"type:"+type;
    }

}
